#!/usr/bin/python

import os
import re
import fnmatch

srcFolder = '/home/zhc/workspaces/workspace/misc_djclubotherdataserver_20130716_optimizeweather/src/server/com/downjoy/app/clubotherdata/server/dao/ibatis/'
destFolder = '/home/zhc/temporary/src/'
filter = '*.java'

for root, dirs, files in os.walk(srcFolder):
    for sfile in files:
        fname = ''
        mtdDict = []
        if fnmatch.fnmatch(sfile, filter):
            fname = 'Test' + sfile
            print (destFolder+fname)
                 
            for line in open(root+sfile).readlines():
                pattern = re.compile('^\s\s*(public).*\s+(\S+)\s*\(.*\).*')
                match = pattern.match(line)
                if match:
                    mtdDict.append(match.group(2)) 
                     
                     
            dfile = open(destFolder+fname, 'w')
            dfile.write('import org.junit.Test;' + os.linesep)
            dfile.write('public class ' + fname[:-5] + '{' + os.linesep)
            for method in mtdDict:
                dfile.write('\t@Test' + os.linesep)
                dfile.write('\tpublic void test' + method + '(){' + os.linesep)
                dfile.write('\t}' + os.linesep)
            dfile.write('}' + os.linesep)
            dfile.flush();
            dfile.close()

